import { Application } from "mydog";
import dbManager from "../../../app/dbManager";
import Doudizhu from "../../../models/doudizhu";
import User from "../../../models/user";

declare global {
  interface Rpc { database: { main: Remote } }
}

export default class Remote {
  private app: Application;
  constructor(app: Application) {
    this.app = app;
  }

  public async registerUser(username: string, password: string): Promise<User | null> {
    return await dbManager.registerUser(username, password);
  }

  public async getUserById(id: number): Promise<User | null> {
    return await dbManager.getUserById(id);
  }

  public async getUserByUsername(username: string): Promise<User | null> {
    return await dbManager.getUserByUsername(username);
  }

  public async rename(uid: number, newname: string): Promise<boolean> {
    return await dbManager.rename(uid, newname);
  }

  public async getDoudizhuInfo(uid: number): Promise<Doudizhu | null> {
    return await dbManager.getDoudizhuInfo(uid);
  }

  public async getUsersJoinDoudizhu(uids: Array<number>) {
    return await dbManager.getUsersJoinDoudizhu(uids);
  }
}
